local skel = fk.CreateSkill {
  name = "emo__aisi",
}

Fk:loadTranslationTable{
  ["emo__aisi"] = "哀思",
  [":emo__aisi"] = "当你受到伤害后，你可以弃置一张牌进行判定，若结果为：<font color='red'>♥</font>，其回复一点体力；<font color='red'>♦</font>，其摸两张牌；♠，来源失去一点体力；♣，来源弃置两张牌。当你死亡时，可令一名角色获得此技能。",

  ["#emo__aisi-invoke"] = "哀思：你受到 %src 的伤害，你可以弃1牌并判定，令你收益或其受损",
  ["#emo__aisi-nosource"] = "哀思：你可以弃1牌并判定，可能令你摸牌或回血",
  ["#emo__aisi-give"] = "你可以令一名角色获得技能“哀思”",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = (data.from and data.from:isAlive()) and ("#emo__aisi-invoke:"..data.from.id) or "#emo__aisi-nosource"
    local room = player.room
    local cards = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = skel.name,
      cancelable = true,
      prompt = prompt,
      skip = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
    if player.dead then return false end
    local pattern = (data.from and data.from:isAlive()) and "." or ".|.|heart,diamond"
    local judge = {
      who = player,
      reason = skel.name,
      pattern = pattern,
    }
    room:judge(judge)
    if not judge.card then return end
    if judge.card.suit == Card.Heart then
      if not player.dead and player:isWounded() then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = skel.name,
        }
      end
    elseif judge.card.suit == Card.Diamond then
      if not player.dead then
        player:drawCards(2, skel.name)
      end
    elseif judge.card.suit == Card.Club then
      if data.from and not data.from.dead then
        room:doIndicate(player, {data.from})
        room:askToDiscard(data.from, {
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = skel.name,
          cancelable = false,
        })
      end
    elseif judge.card.suit == Card.Spade then
      if data.from and not data.from.dead then
        room:doIndicate(player, {data.from})
        room:loseHp(data.from, 1, skel.name)
      end
    end
  end,
})

skel:addEffect(fk.Deathed, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name, false, true) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      max_num = 1, min_num = 1, skill_name = skel.name, cancelable = true, targets = room.alive_players,
      prompt = "#emo__aisi-give"
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:handleAddLoseSkills(to, skel.name)
  end,
})


return skel
